<?php

namespace Modules\Shop\Entities;

use Illuminate\Database\Eloquent\Model;
use houdunwang\arr\Arr;
class Category extends Model
{
	protected $guarded = [];
	public function fenlei(){
		return $this->belongsTo (Category::class,'pid','id');
	}
	public static function getCategory($cate=null){
		$data=self::get();
		if(!is_null($cate)){
			foreach($data as $k=>$v){
				$data[$k]['_selected']=$cate['pid']==$v['id'];
				$data[$k]['_disabled']=$cate['id']==$v['id']||Arr::isChild($data, $v['id'], $cate['id'], 'id', 'pid');
			}
		}
		$arr=Arr::tree($data?$data->toArray():[],'cname','id','pid');
		return $arr;
	}
	public static function hasChildCategory($cate){
		$data=self::get();
		return Arr::hasChild($data, $cate['id'],'pid');

	}
}